{extend name="base"/}
{block name="resources"}
<style>
	#container{height: 500px; }
	.address-content {display: inline-block;vertical-align: top;}
</style>
{/block}
{block name="main"}
<!--<div class="layui-collapse ns-tips">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">操作提示</h2>
		<ul class="layui-colla-content layui-show">
			<li>通过地图定位来填充联系地址或通过点击"查找按钮"来锁定地图上的具体位置</li>
		</ul>
	</div>
</div>-->

<div class="layui-form ns-form" lay-filter="storeform">

	<div class="layui-card ns-card-common ns-card-brief">
		<div class="layui-card-header">
			<span class="ns-card-title">店铺信息</span>
		</div>
		<div class="layui-card-body">
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>店铺名称：</label>
				<div class="layui-input-block">
					<input name="site_name" type="text" lay-verify="required" value="{$info.site_name}" class="layui-input ns-len-long" autocomplete="off">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>店铺分类：</label>
				<div class="layui-input-block ns-len-mid">
					<select class="ns-category" name="category_id" lay-verify="required">
						<option value="">选择主营行业</option>
						{volist name="$shop_category_list" id="category"}
						<option value="{$category.category_id}" {$info.category_id==$category.category_id ? 'selected' : '' }>{$category.category_name}</option>
						{/volist}
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>店铺类型：</label>
				<div class="layui-input-block ns-len-mid">
					<select class="ns-group" name="group_id" lay-filter="group">
						<option value=""></option>
						{volist name="shop_group_list" id="group"}
						<option value="{$group.group_id}" {$info.group_id==$group.group_id ? 'selected' : '' }>{$group.group_name}</option>
						{/volist}
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>省市区：</label>
				<div class="layui-input-inline ns-len-mid area-select">
					<select name="province_id" lay-filter="province_id" lay-verify="province_id">
						<option value="">请选择省份</option>
						{foreach $province_list as $k => $v}
						<option value="{$v.id}">{$v.name}</option>
						{/foreach}
					</select>
				</div>

				<div class="layui-input-inline ns-len-mid area-select">
					<select name="city_id" lay-filter="city_id" lay-verify="city_id">
						<option value="">请选择城市</option>
					</select>
				</div>

				<div class="layui-input-inline ns-len-mid area-select">
					<select name="district_id" lay-filter="district_id" lay-verify="district_id">
						<option value="">请选择区/县</option>
					</select>
				</div>
			</div>



			<div class="layui-form-item">
				<label class="layui-form-label"></label>
				<div class="layui-input-block">
					<input type="text" name="address" placeholder="请输入详细地址，以方便买家联系（请勿重复填写省市区）" lay-verify="address" autocomplete="off" class="layui-input ns-len-long address-content" value="{$info.address}">
					<input type="hidden" name="longitude" lay-verify="required" class="layui-input" value="{$info.longitude}"/>
					<input type="hidden" name="latitude" lay-verify="required" class="layui-input" value="{$info.latitude}"/>
					<button class="layui-btn-primary layui-btn" onclick="refreshFrom();">查找地址</button>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">地图定位：</label>
				<div class="layui-input-block ns-special-length">
					<div id="container" class="selffetch-map"></div>
				</div>
				<div class="ns-word-aux empty-address layui-hide">请选择地理位置！</div>
			</div>


			<div class="layui-form-item">
				<label class="layui-form-label">营业时间：</label>
<!--				<label class="layui-form-label"><span class="required">*</span>营业时间：</label>-->
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="start_time" lay-verify="start_time|required" placeholder="开始时间" value="" readonly >
					<input type="hidden" class="layui-input" name="start_time" placeholder="开始时间" value="{$info.start_time}">
				</div>
				<div class="layui-form-mid layui-word-aux">~</div>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="end_time" lay-verify="end_time|required" placeholder="结束时间" value="" readonly >
					<input type="hidden" class="layui-input" name="end_time" placeholder="结束时间" value="{$info.start_time}">
				</div>

				<!--<div class="layui-input-inline">
					<input type="text" class="layui-input" id="start_time" placeholder="开始时间" autocomplete="off" value="{if $info.start_time} {$info.start_time} {/if}" readonly>
					<i class="ns-calendar"></i>
					<input type="hidden" class="layui-input start-time" name="start_time">
				</div>
				<div class="layui-input-inline">-</div>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="end_time" placeholder="结束时间" autocomplete="off" value="{if $info.end_time} {$info.end_time} {/if}" readonly>
					<i class="ns-calendar"></i>
					<input type="hidden" class="layui-input end-time" name="end_time">
				</div>-->
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>联系人：</label>
				<div class="layui-input-block">
					<input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="{$info.name}">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>联系电话：</label>
				<div class="layui-input-block">
					<input type="number" name="mobile" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="{$info.mobile}">
				</div>
				<div class="ns-word-aux">请输入联系人手机号</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label img-upload-lable">店铺列表图片：</label>
				<div class="layui-input-block img-upload">
					<div class="upload-img-block">
						<div class="upload-img-box {notempty name="$info['avatar']"}hover{/notempty}">
						<div class="ns-upload-default" id="storeUpload">
							{notempty name="$info.avatar"}
							<div id="preview_avatarUpload" class="preview_img">
								<img layer-src src="{:img($info.avatar)}" class="img_prev"/>
							</div>
							{else/}
							<div class="upload">
								<img src="SHOP_IMG/upload_img.png" data-id="avatarUpload"/>
								<p>点击上传</p>
							</div>
							{/notempty}
						</div>
							<div class="operation">
								<div>
									<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
									<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
								</div>
								<div class="replace_img js-replace">点击替换</div>
							</div>
							<input type="hidden" name="avatar" value="{$info.avatar}"/>
						</div>
					</div>
				</div>
				<div class="ns-word-aux">
					<p>建议图片尺寸：160*160像素；图片格式：jpg、png、jpeg。</p>
				</div>
			</div>


			<div class="layui-form-item goods-image-wrap">
				<label class="layui-form-label"><span class="required">*</span>店铺详情图片：</label>
				<div class="layui-input-block">
					<!--商品主图项-->
					<div class="js-goods-image"></div>
					<div class="item js-add-goods-image upload_img_square">+</div>
				</div>
				<!--                <div class="item js-add-goods-image upload_img_square">+</div>-->

				<input type="hidden" name="banner" value="{$info.banner}" />
			</div>


		</div>
	</div>



<!-- 公共部分 -->
<!-- 联系人信息 -->
<div class="layui-card ns-card-common ns-card-brief">
	<div class="layui-card-header">
		<span class="ns-card-title">联系人信息</span>
	</div>
	<div class="layui-card-body">

		<div class="layui-form-item">
			<label class="layui-form-label img-upload-lable ns-company-pic-front">身份证正面：</label>
			<div class="layui-input-block">
				<div class="upload-img-block img-upload">
					<div class="upload-img-box {notempty name="$info['contacts_card_electronic_2']"}hover{/notempty}">
					<div class="ns-upload-default" id="idCardPicFront">
						{notempty name="$info.contacts_card_electronic_2"}
						<div id="preview_idCardUpload" class="preview_img">
							<img layer-src src="{:img($info.contacts_card_electronic_2)}" class="img_prev"/>
						</div>
						{else/}
						<div class="upload">
							<img src="ADMIN_IMG/upload_img.png" data-id="storeUpload"/>
							<p>点击上传</p>
						</div>
						{/notempty}
					</div>
					<div class="operation">
						<div>
							<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
							<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
						</div>
						<div class="replace_img js-replace">点击替换</div>
					</div>
					<input type="hidden" name="contacts_card_electronic_2"  value="{$info.contacts_card_electronic_2}">
				</div>
			</div>
		</div>
		<span class="ns-word-aux">上传申请人身份证正面，即有本人照片与身份证号的那一面</span>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label img-upload-lable ns-company-pic-back">身份证反面：</label>
		<div class="layui-input-block">
			<div class="upload-img-block img-upload">
				<div class="upload-img-box {notempty name="$info['contacts_card_electronic_3']"}hover{/notempty}">
				<div class="ns-upload-default" id="idCardPicBack">
					{notempty name="$info.contacts_card_electronic_3"}
					<div id="preview_idCardPicBack" class="preview_img">
						<img layer-src src="{:img($info.contacts_card_electronic_3)}" class="img_prev"/>
					</div>
					{else/}
					<div class="upload">
						<img src="ADMIN_IMG/upload_img.png" data-id="storeUpload"/>
						<p>点击上传</p>
					</div>
					{/notempty}
				</div>
				<div class="operation">
					<div>
						<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
						<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
					</div>
					<div class="replace_img js-replace">点击替换</div>
				</div>
				<input type="hidden" name="contacts_card_electronic_3" value="{$info.contacts_card_electronic_3}">
			</div>
		</div>
	</div>
	<span class="ns-word-aux">上传申请人身份证反面，即有身份登记地址的那一面</span>
</div>

<div class="layui-form-item">
	<label class="layui-form-label"><span class="required">*</span>证件姓名：</label>
	<div class="layui-input-block">
		<input type="text" name="contacts_card_name"  lay-verify="required" value="{$info.contacts_card_name}" autocomplete="off" class="layui-input  ns-len-long">
	</div>
</div>

<div class="layui-form-item">
	<label class="layui-form-label ns-company-ident">证件号码：</label>
	<div class="layui-input-inline">
		<input name="contacts_card_no" type="text" lay-verify="idcard|required" value="{$info.contacts_card_no}" class="layui-input ns-len-long" autocomplete="off">
	</div>
</div>
<div class="layui-form-item">
	<label class="layui-form-label"><span class="required">*</span>证件类型：</label>
	<div class="layui-input-block ns-len-mid">
		<select name="contacts_card_type" lay-verify="required">
			<option value="">请选择证件类型</option>
			{foreach $id_card_type_list as $id_card_type_list_k => $id_card_type_list_v}
			<option value="{$id_card_type_list_k}" {if $id_card_type_list_k == $info.contacts_card_type}selected {/if}>{$id_card_type_list_v}</option>
			{/foreach}
		</select>
	</div>
</div>

<div class="layui-form-item time-type-view-all" >
	<label class="layui-form-label"><span class="required">*</span>证件有效期：</label>
	<div class="layui-input-inline">
		<input type="text" class="layui-input" id="idCardStartTime" lay-verify="id_card_start_time|required" placeholder="证件有效期开始时间" value="" readonly >
		<input type="hidden" class="layui-input" name="contacts_card_start_time" placeholder="证件有效期开始时间" value="{$info.contacts_card_start_time}">
	</div>
	<div class="layui-form-mid layui-word-aux">~</div>
	<div class="layui-input-inline">
		<input type="text" class="layui-input" id="idCardEndTime" lay-verify="id_card_end_time|required" placeholder="证件有效期结束时间" value="" readonly >
		<input type="hidden" class="layui-input" name="contacts_card_end_time" placeholder="证件有效期结束时间" value="{$info.contacts_card_end_time}">
	</div>
</div>
<!--<div class="layui-form-item">
    <label class="layui-form-label ns-company-name">联系人姓名：</label>
    <div class="layui-input-inline">
        <input name="contacts_name" type="text" class="layui-input ns-len-long" autocomplete="off">
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label ns-company-phone">联系人手机：</label>
    <div class="layui-input-block">
        <input name="contacts_mobile" type="text" lay-verify="mobile" class="layui-input ns-len-long" autocomplete="off">
    </div>
    <span class="ns-word-aux">请填写有效的手机号，如有问题可通过该手机号联系到商家</span>
</div>-->


</div>
</div>

<!-- 开户行信息 -->
<!-- 结算信息 -->
<div class="layui-card ns-card-common ns-card-brief">
	<div class="layui-card-header">
		<span class="ns-card-title">开户行信息</span>
	</div>
	<div class="layui-card-body">

		<!--银行卡-->
		<div class="ns-pay-bank">
			<div class="layui-form-item">
				<label class="layui-form-label ns-pay-alipay-name"><span class="required">*</span>开户人：</label>
				<div class="layui-input-inline">
					<input name="settlement_bank_account_name" id="settlement_bank_account_name"  value="{$info.settlement_bank_account_name}" lay-verify="required" type="text"  class="layui-input ns-len-long" autocomplete="off" lay-verify="required">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>开户行：</label>
				<div class="layui-input-inline">
					<input name="settlement_bank_name" id="settlement_bank_name" type="text"  value="{$info.settlement_bank_name}" lay-verify="required"  class="layui-input ns-len-long" autocomplete="off" lay-verify="required">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label ns-pay-alipay-account"><span class="required">*</span>银行卡号：</label>
				<div class="layui-input-inline">
					<input name="settlement_bank_account_number" id="settlement_bank_account_number" lay-verify="required"  type="text" value="{$info.settlement_bank_account_number}" class="layui-input ns-len-long" autocomplete="off" lay-verify="required">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>银行卡类型：</label>
				<div class="layui-input-block ns-len-mid">
					<select name="settlement_bank_type" lay-verify="required">
						<option value="1" {if $info['settlement_bank_type'] == 1} selected {/if}>对公</option>
						<option value="2" {if $info['settlement_bank_type'] == 2} selected {/if}>对私</option>
						<option value="3" {if $info['settlement_bank_type'] == 3} selected {/if}>对私非法人</option>
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"><span class="required">*</span>银行卡图片：</label>
				<div class="layui-input-block img-upload">
					<div class="upload-img-block">
						<div class="upload-img-box {notempty name="$info['settlement_bank_img']"}hover{/notempty}">
						<div class="ns-upload-default" id="bankUpload">
							{notempty name="$info.settlement_bank_img"}
							<div id="preview_bankUpload" class="preview_img">
								<img layer-src src="{:img($info.settlement_bank_img)}" class="img_prev"/>
							</div>
							{else/}
							<div class="upload">
								<img src="ADMIN_IMG/upload_img.png" data-id="bankUpload"/>
								<p>点击上传</p>
							</div>
							{/notempty}
						</div>
						<div class="operation">
							<div>
								<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
								<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
							</div>
							<div class="replace_img js-replace">点击替换</div>
						</div>
						<input type="hidden" name="settlement_bank_img" value="{$info.settlement_bank_img}">
					</div>
				</div>
			</div>
		</div>

			<!--<div class="layui-form-item" data-flag="area" hidden>
				<label class="layui-form-label"><span class="required">*</span>结算开户银行所在地：</label>
				<div class="layui-input-inline">
					<input name="settlement_bank_address" id="settlement_bank_address" type="text" value="" class="layui-input ns-len-long" autocomplete="off" lay-verify="required">
				</div>
			</div>-->
		</div>


	</div>
</div>



		{if $info.cert_type == 2}
		<div class="ns-store-company ">
			<div class="layui-card ns-card-common ns-card-brief">
				<div class="layui-card-header">
					<span class="ns-card-title">营业执照</span>
				</div>
				<div class="layui-card-body">


					<div class="layui-form-item">
						<label class="layui-form-label img-upload-lable">营业执照：</label>
						<div class="layui-input-block">
							<div class="upload-img-block img-upload">
								<div class="upload-img-box {notempty name="$info['business_licence_number_electronic']"}hover{/notempty}"">
								<div class="ns-upload-default" id="license">
									{notempty name="$info.business_licence_number_electronic"}
									<div id="preview_frontPicUpload" class="preview_img">
										<img layer-src src="{:img($info.business_licence_number_electronic)}" class="img_prev"/>
									</div>
									{else/}
									<div class="upload">
										<img src="ADMIN_IMG/upload_img.png" data-id="frontPicUpload"/>
										<p>点击上传</p>
									</div>
									{/notempty}
								</div>
								<div class="operation">
									<div>
										<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
										<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
									</div>
									<div class="replace_img js-replace">点击替换</div>
								</div>
								<input type="hidden" name="business_licence_number_electronic" value="{$info.business_licence_number_electronic}">
							</div>
						</div>
					</div>
					<span class="ns-word-aux">请上传营业执照传真图片或者照片，营业执照包括边框内容要全部显示，不能遮挡</span>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">统一社会信用码：</label>
					<div class="layui-input-block">
						<input name="business_licence_number" type="text" class="layui-input ns-len-long" autocomplete="off" value="{$info.business_licence_number}">
					</div>
					<span class="ns-word-aux">请填写三证合一之后的营业执照上的统一社会信用代码</span>
				</div>

				<div class="layui-card-body">
					<div class="layui-form-item">
						<label class="layui-form-label">有效期类型：</label>
						<div class="layui-input-block" id="license_time_type">
							<input type="radio" name="license_time_type" lay-filter="licenseTimeType" value="1" title="长期有效" {if $info.license_time_type == 1} checked {/if}>
							<input type="radio" name="license_time_type" lay-filter="licenseTimeType" value="0" title="有期限" {if $info.license_time_type == 0} checked {/if}>
						</div>
					</div>
				</div>

				<div class="layui-form-item" id="license_time">
					<label class="layui-form-label">证件有效期：</label>
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="businessLicenseStartTime" lay-verify="business_license_start_time" placeholder="营业执照开始时间" value="" readonly >
						<input type="hidden" class="layui-input" name="license_start_date" placeholder="开始时间" value="{$info.license_start_date}">
					</div>
					<div class="layui-form-mid layui-word-aux">~</div>
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="businessLicenseEndTime" lay-verify="business_license_end_time" placeholder="营业执照结束时间" value="" readonly >
						<input type="hidden" class="layui-input" name="license_end_date" placeholder="结束时间" value="{$info.license_end_date}">
					</div>
				</div>



			</div>
		</div>
		</div>
		{/if}



	
	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
	</div>

</div>

<script type="text/html" id="houseNumberImage">
	{{# if(d.list.length){ }}
	{{# for(var i=0;i<d.list.length;i++){ }}
	<div class="item upload_img_square_item" data-index="{{i}}">
		<div class="img-wrap">
			<img src="{{ns.img(d.list[i])}}" layer-src>
		</div>
		<div class="operation">
			<i title="图片预览" class="iconfont iconreview js-preview"></i>
			<i title="删除图片" class="layui-icon layui-icon-delete js-delete" data-index="{{i}}"></i>
			<!--            <div class="replace_img img_show" data-index="{{i}}">点击替换</div>-->
		</div>
	</div>
	{{# } }}

	{{# } }}

</script>
{/block}

{block name="script"}
<script type="text/javascript">
	window._AMapSecurityConfig = {
		securityJsCode:'32f0302062f41190e845f1ab073cda3b',
	}
</script>
<script type="text/javascript" src="{:get_http_type()}://webapi.amap.com/maps?v=1.4.6&amp;key={if empty($map_key['gaode_map_key'])}af48136f5a3f33efe58cb118e0ea139c{else/}{$map_key['gaode_map_key']}{/if}"></script>
<script type="text/javascript" src="SHOP_JS/address.js"></script>
<script type="text/javascript" src="STATIC_JS/map_address.js"></script>
<script src="ADMIN_JS/address.js"></script>
<script src="__STATIC__/ext/drag-arrange.js"></script>
<script type="text/javascript">
	var houseNumberImage = [];//详情图片
	const GOODS_IMAGE_MAX = 8;//商品主图数量
	var laytpl;
	var form, laydate, repeat_flag, map_class;
	
	/**
	 * 初始化营业时间
	 */
	/*var startTime = "{$info.start_time}",
		endTime = "{$info.end_time}";
	if (Number(startTime)){
		$("#start_time").val(ns.time_to_date(startTime, "h:m:s"));
		$(".start-time").val(startTime);
	}
	
	if (Number(endTime)){
		$("#end_time").val(ns.time_to_date(endTime, "h:m:s"));
		$(".end-time").val(endTime);
	}*/

	layui.use(['laydate', 'form','upload','laytpl'], function() {
		var upload = layui.upload;
		laytpl = layui.laytpl;
		form = layui.form;
		laydate = layui.laydate;
		repeat_flag = false;//防重复标识
		
		//form.render();

		houseNumberImage = $("input[name='banner']").val().split(",");
		refresHouseNumberImage();
		
		if('{$info.latitude}' == "" || '{$info.longitude}' == ""){
		    var latlng = {lat:'',lng:''};
		}else{
		    var latlng = {lat:'{$info.latitude}',lng:'{$info.longitude}'};
		}

		//初始化联系地址
		var initdata = {province_id : '{$info.province}', city_id : '{$info.city}', district_id : '{$info.district}'};
		initAddress(initdata, "storeform");

		//初始化工作日
		var workWeek = "{$info.work_week}",
			workArr = workWeek.split(",");

		for (var i = 0; i < workArr.length; i++){
			$("input[name=work_week"+ workArr[i] +"]").prop("checked",true);
		}
		
		//form.render();

		//地图展示
		map_class = new mapClass("container", latlng);
		form.render();
		
		//获取 - 开始时间
		var start_hours, start_minutes, start_seconds;
		laydate.render({
			elem: '#start_time',
			type: 'time',
			value: "{:date('H:i', strtotime(date('Y-m-d')) + $info.start_time)}",
			format:'HH:mm',
			done: function(value, date){
				var time = date.hours * 3600 + date.minutes * 60 + date.seconds;
				$("input[name=start_time]").val(time);
				/*start_hours = date.hours;
				start_minutes = date.minutes;
				start_seconds = date.seconds;
				$(".start-time").val(ns.date_to_time(date.year + "-" + date.month + "-" + date.date + " " + date.hours + ":" + date.minutes + ":" + date.seconds))*/
			}
		});
		
		//获取 - 结束时间
		laydate.render({
			elem: '#end_time',
			type: 'time',
			value: "{:date('H:i', strtotime(date('Y-m-d')) + $info.end_time)}",
			format:'HH:mm',
			done: function(value, date){
				//$(".end-time").val(ns.date_to_time(date.year + "-" + date.month + "-" + date.date + " " + date.hours + ":" + date.minutes + ":" + date.seconds))
				var time = date.hours * 3600 + date.minutes * 60 + date.seconds;
				$("input[name=end_time]").val(time);
			}
		});

		laydate.render({
			elem: '#idCardStartTime',
			type: 'date',
			value: "{$info.contacts_card_start_time}",
			format:'yyyy-MM-dd',
			done: function(value) {
				$("input[name=contacts_card_start_time]").val(value);
			}
		});

		laydate.render({
			elem: '#idCardEndTime',
			type: 'date',
			value: "{$info.contacts_card_end_time}",
			format:'yyyy-MM-dd',
			done: function(value) {
				$("input[name=contacts_card_end_time]").val(value);
			}
		});

		laydate.render({
			elem: '#businessLicenseStartTime',
			type: 'date',
			value: "{$info.license_start_date}",
			format:'yyyy-MM-dd',
			done: function(value) {
				$("input[name=license_start_date]").val(value);
			}
		});

		laydate.render({
			elem: '#businessLicenseEndTime',
			type: 'date',
			value: "{$info.license_end_date}",
			format:'yyyy-MM-dd',
			done: function(value) {
				$("input[name=license_end_date]").val(value);
			}
		});

		upload.render({
			elem: '.js-add-goods-image' //绑定元素
			,url:ns.url('shop/upload/upload')
			,accept: 'images' //上传图片
			,multiple: true //允许多文件上传
			,before: function(obj){
				//do something
				console.error(obj)
			}
			,done: function(res){
				console.error(res)
				//上传完毕回调
				if(res.code > 0){ //假设成功返回的code为0
					if (houseNumberImage.length < GOODS_IMAGE_MAX) houseNumberImage.push(res.data.pic_path);
					refresHouseNumberImage();
				}
			}
			,error: function(){
				//请求出错处理
			}
		});

		var store_upload = new Upload({
			elem: '#storeUpload',
			url: ns.url("shop/upload/upload"),
		});

		form.on('submit(save)', function(data) {

			if( data.field.longitude == "" || data.field.latitude == ""){
			    layer.msg('请确认地理位置!');
			    $(".empty-address").removeClass("layui-hide");
			    return;
			}else{
			    $(".empty-address").addClass("layui-hide");
			}
			
			var province_name = $("select[name=province_id] option:selected").text();
			var city_name = $("select[name=city_id] option:selected").text();
			var district_name = $("select[name=district_id] option:selected").text();
			
			//地址id
			data.field.province = data.field.province_id;
			data.field.city = data.field.city_id;
			data.field.district = data.field.district_id;
			data.field.community = data.field.community_id;
			
			//地址name
			data.field.province_name = province_name;
			data.field.city_name = city_name;
			data.field.district_name = district_name;
			
			data.field.full_address = province_name + city_name + district_name;

			data.field.banner = houseNumberImage.toString();

			if(!data.field.avatar) store_upload.delete();

			//工作日
			var week_arr = [];
			$("#work_week input").each(function () {
				if ($(this).is(":checked")) {
					week_arr.push($(this).val());
				}
			});
			data.field.work_week = week_arr.toString();
			
			if ($("#start_time").val() > $("#end_time").val()) {
				layer.msg("结束时间不能小于开始时间！");
				return;
			}

			data.field.category_name = $("select[name=category_id] option:selected").text();
			data.field.group_name = $("select[name=group_id] option:selected").text();
 
			if (repeat_flag) return;
			repeat_flag = true;
			
			$.ajax({
				url: ns.url("shop/shop/contact"),
				data: data.field,
				type: "POST",
				dataType: "JSON",
				success: function(res) {
					repeat_flag = false;
					layer.msg(res.message);
					if (res.code == 0) {
						location.reload();
					}
				}
			});
		});

		//表单验证
		form.verify({
			province_id : function(value, item){
			    if(value == ''){
			        return '请选择省份';
			    }
			},
			city_id : function(value, item){
			    if(value == ''){
			        return '请选择城市';
			    }
			},
			district_id : function(value, item){
			    if(value == ''){
			        return '请选择区/县';
			    }
			},
			community_id : function(value, item){
			    if(value == ''){
			        return '请选择街道';
			    }
			},
			address: function(value) {
				if (value == '') {
					return '请输入详细地址';
				}
			},
		});
	});

	/**
	 * 重新渲染表单
	 */
	function refreshFrom(){
	    form.render();
	    orderAddressChange();//改变地址
	    map_class.mapChange();
	}
	
	//动态改变订单地址赋值
	function orderAddressChange(){
	    map_class.address.province = $("select[name=province_id]").val();
	    map_class.address.province_name = $("select[name=province_id] option:selected").text();
	    map_class.address.city = $("select[name=city_id]").val();
	    map_class.address.city_name = $("select[name=city_id] option:selected").text();
	    map_class.address.district = $("select[name=district_id]").val();
	    map_class.address.district_name = $("select[name=district_id] option:selected").text();
	    map_class.address.township = $("select[name=community_id]").val();
	    map_class.address.township_name = $("select[name=community_id] option:selected").text();
	    map_class.address.address = $("input[name=address]").val()
	}

	/**
	 * 地址下拉框（主要用于坐标记录）
	 */
	function selectCallBack(){
	    $("input[name=longitude]").val(map_class.address.longitude);//坐标
	    $("input[name=latitude]").val(map_class.address.latitude);//坐标
	}

	//地图点击回调事件
	function mapChangeCallBack(){
	    $("input[name=address]").val(map_class.address.address);//详细地址
	    $("input[name=longitude]").val(map_class.address.longitude);//坐标
	    $("input[name=latitude]").val(map_class.address.latitude);//坐标

	    $.ajax({
	        type : "POST",
	        dataType: 'JSON',
	        url : ns.url("shop/address/getGeographicId"),
	        async : true,
	        data : {
	            "address" : map_class.address.area
	        },
	        success : function(data) {
				map_class.address.province = data.province_id;
	            map_class.address.city = data.city_id;
	            map_class.address.district = data.district_id;
	            map_class.address.township = data.subdistrict_id;
	            map_class.map_change = false;
	            form.val("storeform", {
	                "province_id": data.province_id
	            });
	            $("select[name=province_id]").change();
	            form.val("storeform", {
	                "city_id": data.city_id
	            });
	            $("select[name=city_id]").change();
	            form.val("storeform", {
	                "district_id": data.district_id
	            });
	            $("select[name=district_id]").change();
	            form.val("storeform", {
	                "community_id": data.subdistrict_id
	            });
	            refreshFrom();//重新渲染form
	            map_class.map_change = true;
	        }
	    });
	}

	//渲染门牌号主图列表
	function refresHouseNumberImage() {
		var goods_image_template = $("#houseNumberImage").html();
		var data = {
			list: houseNumberImage,
			max: GOODS_IMAGE_MAX
		};

		laytpl(goods_image_template).render(data, function (html) {

			$(".js-goods-image").html(html);

			//加载图片放大
			loadImgMagnify();

			if (houseNumberImage.length) {

				//预览
				$(".js-goods-image .js-preview").click(function () {
					$(this).parent().prev().find("img").click();
				});

				//图片删除
				$(".js-goods-image .js-delete").click(function () {
					var index = $(this).attr("data-index");
					houseNumberImage.splice(index, 1);
					refresHouseNumberImage();
				});

				// 拖拽
				$('.js-goods-image .upload_img_square_item').arrangeable({
					//拖拽结束后执行回调
					callback: function (e) {
						var indexBefore = $(e).attr("data-index");//拖拽前的原始位置
						var indexAfter = $(e).index();//拖拽后的位置
						var temp = houseNumberImage[indexBefore];
						houseNumberImage[indexBefore] = houseNumberImage[indexAfter];
						houseNumberImage[indexAfter] = temp;
						refresHouseNumberImage();
					}
				});
			}

			//最多传十张图
			if (houseNumberImage.length < GOODS_IMAGE_MAX) {
				$(".js-add-goods-image").show();
			} else {
				$(".js-add-goods-image").hide();
			}


		});
	}
</script>
{/block}